<template>
  <div class="report-form-content">
    <div class="tabs-form-head">
      <span>合同验收</span>
      <div class="">
        <el-button type="primary" plain @click="returnBtn">返回</el-button>
      </div>
    </div>
    <el-divider border-style="dashed" />
    <el-row :gutter="20">
      <el-col :sm="24" :lg="24" style="padding-left: 20px">
        <el-card class="update-log">
          <el-table :data="objList"
                    style="width: 100%; margin-top: 20px"
                    row-key="id"
                    border
                    default-expand-all>
            <el-table-column label="内容" prop="content" />
            <el-table-column label="负责人" width="150">
              <template v-slot="{row}">
                {{ showIdLabel(userList, row.principalUserId, 'name') }}
              </template>
            </el-table-column>
            <el-table-column label="监理">
              <template v-slot="{row}">
                {{ showIdLabel(userList, row.supervisorUserId, 'name') }}
              </template>
            </el-table-column>
            <el-table-column label="验收时间" prop="checkingTime" />
            <el-table-column label="验收意见" prop="checkingComment" />
            <el-table-column label="审批方式" prop="aaa">
              <template v-slot="{row}">
                {{ row.approvalMethod === '1' ? '线上审批' : '线下审批' }}
              </template>
            </el-table-column>
          </el-table>
        </el-card>
        <el-card class="update-log">
          <!-- 附件信息 -->
          <el-table :data="objList"
                    style="width: 100%; margin-top: 20px"
                    row-key="id"
                    border
                    default-expand-all>
            <el-table-column align="center" label="验收附件" min-width="250px">
              <template v-slot="scope">
                <ul class="files-url">
                  <li class="files-green" v-for="item1 in scope.row.attachments" :key="item1.id" v-show="item1.attachmentType === '01'">
                    <div class="file-text" v-if="item1.attachmentType === '01'">
                      <div>
                        <span class="file-name">{{ item1.attachmentName }}</span>
                        <span class="file-kb">{{ bytesToSize(item1.attachmentSize) }}</span>
                      </div>
                      <div>
                        <span class="file-time">{{ showIdLabel(userList, item1.attachmentUploader, 'name') }}<span style="color:#333;">上传于</span>{{ item1.attachmentUpload }}</span>
                      </div>
                    </div>
                    <div class="file-btn">
                      <el-button type="primary" link @click="downloadFile(item1)">下载</el-button>
                      <el-button type="primary" link @click="handlePreview(item1)">预览</el-button>
                    </div>
                  </li>
                </ul>
              </template>
            </el-table-column>
            <el-table-column align="center" label="签名/盖章附件" min-width="250px">
              <template v-slot="scope">
                <ul class="files-url">
                  <li class="files-green" v-for="item1 in scope.row.attachments" :key="item1.id" v-show="item1.attachmentType === '02'">
                    <div class="file-text">
                      <div>
                        <span class="file-name">{{ item1.attachmentName }}</span>
                        <span class="file-kb">{{ bytesToSize(item1.attachmentSize) }}</span>
                      </div>
                      <div>
                        <span class="file-time">{{ showIdLabel(userList, item1.attachmentUploader, 'name') }}<span style="color:#333;">上传于</span>{{ item1.attachmentUpload }}</span>
                      </div>
                    </div>
                    <div class="file-btn">
                      <el-button type="primary" link @click="downloadFile(item1)">下载</el-button>
                      <el-button type="primary" link @click="handlePreview(item1)">预览</el-button>
                    </div>
                  </li>
                </ul>
              </template>
            </el-table-column>
            <el-table-column align="center" label="验收结果附件" min-width="250px">
              <template v-slot="scope">
                <ul class="files-url">
                  <li class="files-green" v-for="item1 in scope.row.attachments" :key="item1.id" v-show="item1.attachmentType === '03'">
                    <div class="file-text">
                      <div>
                        <span class="file-name">{{ item1.attachmentName }}</span>
                        <span class="file-kb">{{ bytesToSize(item1.attachmentSize) }}</span>
                      </div>
                      <div>
                        <span class="file-time">{{ showIdLabel(userList, item1.attachmentUploader, 'name') }}<span style="color:#333;">上传于</span>{{ item1.attachmentUpload }}</span>
                      </div>
                    </div>
                    <div class="file-btn">
                      <el-button type="primary" link @click="downloadFile(item1)">下载</el-button>
                      <el-button type="primary" link @click="handlePreview(item1)">预览</el-button>
                    </div>
                  </li>
                </ul>
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </el-col>
    </el-row>
    <el-dialog v-model="attachmentVisible" title="附件预览" width="70%" top="2vh">
      <attachmentPreview :attachmentId="previewAttachmentId" />
      <div style="text-align:right;">
        <el-button type="danger" @click="attachmentVisible = false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script setup>
import {getCurrentInstance, ref} from 'vue'
import {doGet, doGetDownload} from "@/config/http";
import {svc, showIdLabel, getListPageSize, bytesToSize} from "@/config/common";
import attachmentPreview from '@/views/components/base/attachmentPreview.vue'
import { useRoute } from 'vue-router'
import initListStore from '@/store/modules/initList'

const route = useRoute()

const { proxy: ctx } = getCurrentInstance();

let objList = ref([])

let attachmentVisible = ref(false)
let previewAttachmentId = ref('')
let selectAttachmentVisible = ref(false)

// let contractTypeList = ref([]) // 合同类型
// let contractCooperationList = ref([]) // 往来单位
// let contractFeetypeList = ref([]) // 合同费用类型
// let contractTemplateList = ref([]) // 合同模版
// let bankList = ref([]) // 银行
let userList = initListStore().userList // 用户
// let governmentList = ref([]) //  政府单位
// let organizationList = ref([]) // 部门
// let contractSignerList = ref([]) // 签订人
// let contractFiletypeList = ref([]) // 合同附件类型
// const initList = async () => {
//   let p1 = doGet(svc, '/contract-type/page', {pageSize: getListPageSize()}, false) // 合同类型
//   let p2 = doGet(svc, '/contract-cooperation/page', {pageSize: getListPageSize()}, false) // 往来单位
//   let p3 = doGet(svc, '/contract-feetype/page', {pageSize: getListPageSize()}, false) // 合同费用类型
//   let p4 = doGet(svc, '/contract-template/page', {pageSize: getListPageSize()}, false) // 合同模版
//   let p5 = doGet(svc, '/bank/page', {pageSize: getListPageSize()}, false) // 银行
//   let p6 = doGet(svc, '/user/page', {pageSize: getListPageSize()}, false) // 用户
//   let p7 = doGet(svc, '/government/page', {pageSize: getListPageSize()}, false) //  政府单位
//   let p8 = doGet(svc, '/organization/page', {pageSize: getListPageSize()}, false) // 部门
//   let p9 = doGet(svc, '/contract-signer/page', {pageSize: getListPageSize()}, false) // 签订人
//   let p10 = doGet(svc, '/contract-filetype/page', {pageSize: getListPageSize()}, false) // 合同附件类型

//   let resArray = await Promise.all([p1, p2, p3, p4, p5, p6, p7, p8, p9, p10])
//   contractTypeList.value = resArray[0]['records']
//   contractCooperationList.value = resArray[1]['records']
//   contractFeetypeList.value = resArray[2]['records']
//   contractTemplateList.value = resArray[3]['records']
//   bankList.value = resArray[4]['records']
//   userList.value = resArray[5]['records']
//   governmentList.value = resArray[6]['records']
//   organizationList.value = resArray[7]['records']
//   contractSignerList.value = resArray[8]['records']
//   contractFiletypeList.value = resArray[9]['records']
// }

const initObj = async () =>  {
  if (route.query.id) {
    // obj.value = await doGet(svc, '/contract-initial/' + route.query.id, {}, true)
    // 验收条件
    objList.value = await doGet(svc, '/contract-initial-checking/listByField', {field: 'contractInitialId', values: route.query.id}, true)
  }
}

// initList()
initObj()

const downloadFile = (row) => {
  doGetDownload(svc, '/customAttachment/download/' + row.attachmentId, {})
}
const handlePreview = (file) => {
  attachmentVisible.value = true
  setTimeout(() => {
    previewAttachmentId.value = file.attachmentId
  },100)
}

const returnBtn = () => {
  switch (route.query.kind) {
    case '1':
      ctx.goTargetByName('contractInitial', {});
      break;
    case '2':
      ctx.goTargetByName('contractMain', {})
      break;
  }
}
</script>
<style scoped>
.report-form-content {
  padding: 20px;
}
.update-log {
  width: 100%;
  margin: 30px 0;
}
.tabs-form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tabs-form-head span {
  font-size: 18px;
  color: #303133;
  font-weight: bold;
}
.files-url {
  list-style-type: none;
  margin: 0;
  padding: 0;
  text-align: left;
}
.files-url li {
  list-style-type: none;
  margin: 5px;
  padding: 0;
}
.files-url li.files-green {
  border: 1px solid #1ab394;
  background-color: #eaffea;
}
.files-url li.files-red {
  border: 1px solid #F56C6C;
  background-color: #fcf3f3;
}
.files-url li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px;
}
.files-url li span {
  padding: 0 5px;
  font-size: 12px;
  font-weight: bold;
}
.update-log {
  width: 100%;
  margin: 30px 0;
}
</style>
